// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Microsoft.EntityFrameworkCore.Migrations;

namespace UserSessionDb.Migrations.UserSessions;

public partial class UserSessions : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "UserSessions",
            columns: table => new
            {
                Id = table.Column<long>(type: "INTEGER", nullable: false)
                    .Annotation("Sqlite:Autoincrement", true),
                ApplicationName = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true),
                SubjectId = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
                SessionId = table.Column<string>(type: "TEXT", nullable: true),
                Created = table.Column<DateTime>(type: "TEXT", nullable: false),
                Renewed = table.Column<DateTime>(type: "TEXT", nullable: false),
                Expires = table.Column<DateTime>(type: "TEXT", nullable: true),
                Ticket = table.Column<string>(type: "TEXT", nullable: false),
                Key = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_UserSessions", x => x.Id);
            });

        migrationBuilder.CreateIndex(
            name: "IX_UserSessions_ApplicationName_Key",
            table: "UserSessions",
            columns: new[] { "ApplicationName", "Key" },
            unique: true);

        migrationBuilder.CreateIndex(
            name: "IX_UserSessions_ApplicationName_SessionId",
            table: "UserSessions",
            columns: new[] { "ApplicationName", "SessionId" },
            unique: true);

        migrationBuilder.CreateIndex(
            name: "IX_UserSessions_ApplicationName_SubjectId_SessionId",
            table: "UserSessions",
            columns: new[] { "ApplicationName", "SubjectId", "SessionId" },
            unique: true);

        migrationBuilder.CreateIndex(
            name: "IX_UserSessions_Expires",
            table: "UserSessions",
            column: "Expires");
    }

    protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable(
            name: "UserSessions");
}
